package org.k.vmmock.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by hengxianwang on 16-10-30.
 */
public class Conf {
    public static final String PAGE_DIR = "page_dir";
    public static final String TEST_DIR = "test_dir";
    public static final String WEB_XML_PATH = "web_xml_path";
    public static final String ROUTERS_FILE = "routers_file";

    private static Properties properties;
    //
    public static String basePath = "";
    public static int port = 8080;
    static {
        properties = new Properties();
        InputStream in = null;
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
        try {
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(in != null) try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static String get(String k){
        return properties.getProperty(k);
    }

    public static String getBasePath(boolean endOfSlash){
        boolean yes = basePath.endsWith("/");
        if((yes && endOfSlash) || (!yes && !endOfSlash)) return basePath;
        if(!yes && endOfSlash) return basePath + "/";
        if(yes && !endOfSlash) return basePath.substring(0, basePath.length() - 1);
        return "";
    }

}
